package com.caogen.cg_wl_kt.vmodel.fragment

import androidx.lifecycle.MutableLiveData
import com.caogen.cg_wl_kt.base.BaseViewModel
import com.caogen.cg_wl_kt.base.Gl
import com.caogen.cg_wl_kt.model.home.HomeListBean
import com.caogen.cg_wl_kt.ui.fragment.home.HomeFragment
import com.caogen.cg_wl_kt.utils.Toasts
import com.caogen.cg_wl_kt.utils.YDLog

class HomeViewModel : BaseViewModel() {
    var activity: HomeFragment? = null
    val data: MutableLiveData<MutableList<HomeListBean>>? =  MutableLiveData()
    val list: MutableList<HomeListBean> = mutableListOf()
    fun getListData(){
        if (page == 1){
            list.clear()
        }
        val test: MutableList<HomeListBean> = mutableListOf()
        for (i in 0..5){
            var bean = HomeListBean();
            bean.id = "$i"
            bean.title = "$i"
            bean.sub = "$i---e"
            test.add(bean)
        }
        list.addAll(test)
        if (page_size > test.size){
            activity?.toast("无更多数据！")

            activity?.binding?.refreshLayout?.finishRefresh()//停止刷新
        }
        if (page == 1){
            activity?.binding?.refreshLayout?.finishRefresh(0/*,false*/)//传入false表示刷新失败
        }else{
            activity?.binding?.refreshLayout?.finishLoadMore(0/*,false*/)//传入false表示加载失败
        }

        data?.value = list
        activity?.adapter?.setData(list)

        YDLog.logd(list.toString())
    }

}